package _12_lianxi;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Cow {

	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		List<Cow1> cow = new ArrayList<Cow1>();
		Cow1 c1 = new Cow1("123001", "奶牛", 5);
		Cow1 c2 = new Cow1("123002", "母牛", 4);
		Cow1 c3 = new Cow1("123003", "公牛", 6);
		cow.add(c1);
		cow.add(c2);
		cow.add(c3);
		System.out.println("排序前 : ");
		for (Object object : cow) {
			System.out.println(object);
		}
		Collections.sort(cow, new Comparator() {

			@Override
			public int compare(Object o1, Object o2) {
				// TODO Auto-generated method stub
				return ((Cow1) o1).getAge() - ((Cow1) o2).getAge();
			}
		});
		System.out.println("排序后 : ");
		for (Object object : cow) {
			System.out.println(object);
		}
	}

}

class Cow1 {
	private String number;
	private String name;
	private int age;

	public String getNumber() {
		return number;
	}

	public void setNumber(String number) {
		this.number = number;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public Cow1() {
		super();
		// TODO Auto-generated constructor stub
	}

	public Cow1(String number, String name, int age) {
		super();
		this.number = number;
		this.name = name;
		this.age = age;
	}

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return "编号 : " + number + " , 姓名 : " + name + " , 年龄 : " + age;
	}
}